package net.qiqbframework.event.dao.mfimpl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import net.qiqbframework.common.dto.PageResultDto;
import net.qiqbframework.common.utils.StringUtils;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionDao;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionPageCondition;
import net.qiqbframework.eventsourcing.dao.DomainEventSubscriptionPo;
import net.qiqbframework.mf.BasicEntityPoDaoMfImpl;
import net.qiqbframework.mf.MpUtil;

import java.util.List;

public class DomainEventSubscriptionDaoMfImpl extends BasicEntityPoDaoMfImpl<DomainEventSubscriptionMapper, DomainEventSubscriptionPo> implements DomainEventSubscriptionDao {
    @Override
    public PageResultDto<DomainEventSubscriptionPo> list4Page(DomainEventSubscriptionPageCondition condition) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DomainEventSubscriptionPo::getEventId, condition.getEventId()).like(DomainEventSubscriptionPo::getApplicationName, condition.getApplicationName(), StringUtils.nonEmptyOrNull(condition.getInstanceName())).like(DomainEventSubscriptionPo::getInstanceName, condition.getInstanceName(), StringUtils.nonEmptyOrNull(condition.getInstanceName()))

        ;
        final Page<DomainEventSubscriptionPo> page = super.page(MpUtil.ofPage(condition), queryWrapper);
        return MpUtil.toResult(page);
    }

    @Override
    public List<DomainEventSubscriptionPo> listByEventId(String eventId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DomainEventSubscriptionPo::getEventId, eventId);
        return super.list(queryWrapper);
    }

}
